def words_to_number(words):
    word_to_digit = {
        "zero": "0", "one": "1", "two": "2", "three": "3", "four": "4",
        "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"
    }
    
    digits = []
    for word in words:
        if word in word_to_digit:
            digits.append(word_to_digit[word])
        else:
            return None
    
    number_str = ''.join(digits)
    number = int(number_str)
    
    if 100 <= number <= 999:
        return number
    else:
        return None

def is_prime(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            return False
    return True

def closest_prime(n):
    if is_prime(n):
        return n
    
    lower = n - 1
    upper = n + 1
    
    while True:
        if is_prime(lower):
            return lower
        if is_prime(upper):
            return upper
        lower -= 1
        upper += 1

def main():
    input_str = input().strip()
    words = input_str.split()
    
    if len(words) != 3:
        print("Wrong input")
        return
    
    number = words_to_number(words)
    
    if number is None:
        print("Wrong input")
    else:
        print(closest_prime(number))

if _name_ == "_main_":
    main()